package midtool;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.Callable;

import javax.swing.plaf.FileChooserUI;

import org.apache.commons.io.FileUtils;
import org.jfugue.midi.MidiFileManager;
import org.jfugue.pattern.Pattern;
import org.jfugue.player.Player;

import com.attilax.collection.listBuilder;
import com.attilax.util.timestampUtil;
import com.google.common.base.Joiner;

public class midBuild {
	
	public static void main(String[] args) throws Exception {
	
	//	String s="  1155665-  4433221-  5544332-    5544332-     1155665-    4433221-";//  5544332    5544332     1155665    4433221
		
	//	String	s="3333333- 33333 3333-";
		
	//	ysheyshelyojinjin();
		
	//	String	s=	"E5q B5q A5q B5q      A5q B5q b5h        G5i A5i B5i E5i G5i E5i";
		String	s="1155665  4433221";
		s=FileUtils.readFileToString(new File("C:\\mp3jyepu.txt"));
		String fnal_s=s;
	  	Player player = new Player();
	 	player.play( new Callable<Pattern>() {

			@Override
			public Pattern call() throws Exception {
				Pattern Pattern1 = new Pattern();   
				String joinSpaceAfted =jyepuUtil. getMidiStr(fnal_s);
				Pattern1.add(joinSpaceAfted);  
				return Pattern1;
			}
		} .call() );
	}

	private static void ysheyshelyojinjin() throws Exception  {
		String s="  1155665-  4433221-  5544332-    5544332-     1155665-    4433221-";
	
		  	Player player = new Player();
		 	player.play( new Callable<Pattern>() {

				@Override
				public Pattern call() throws Exception {
					Pattern Pattern1 = new Pattern();   
					String joinSpaceAfted =jyepuUtil. getMidiStr(s);
					Pattern1.add(joinSpaceAfted);  
					saveMidi(Pattern1);
					return Pattern1;
				}
			} .call() );
		 	
		 	
		 	
		
	}

	protected static void saveMidi(Pattern pattern1) throws IOException {

	 	String asTimeStamp_millsec_filenameencode = timestampUtil.join("c:\\0log\\atifirstmid-@ins@-@tmstmp@.mid").asTimeStamp_millsec_filenameencode();
		FileUtils.forceMkdirParent(new File(asTimeStamp_millsec_filenameencode));
			//	asTimeStamp_millsec_filenameencode=asTimeStamp_millsec_filenameencode.replaceAll("@ins@", ins);
				File file = new File( asTimeStamp_millsec_filenameencode );
			 	new MidiFileManager().savePatternToMidi(pattern1, file);
		
	}



}
